//
//  ERequestAppInfo.m
//  AppRanking
//
//  Created by Gang.Wang on 12-11-8.
//  Copyright (c) 2012年 Gang.Wang. All rights reserved.
//

#import "ERequestAppInfo.h"
#import "mcf.h"


#define _GET_APPIFNO_URL_TEMPLATE_              @"https://itunes.apple.com/lookup?id=%%appid%%"
#define _GET_APPINFO_URL_APPID_PARAM_           @"%%appid%%"

@interface ERequestAppInfo(Private)

- (void) generateDownloadModel;
- (NSString *) getAppInfoApi:(NSString *) appId;

@end

@implementation ERequestAppInfo

@synthesize appId = appId_;

- (void) dealloc
{
    YRelease(appId_)
    [super dealloc];
}

- (void) setAppId:(NSString *)appIdValue
{
    YRelease(appId_)
    appId_ = [appIdValue copy];
    
    [self generateDownloadModel];
}

#pragma mark - Private Method
- (void) generateDownloadModel
{
    if([NSString isNilOrEmpty:self.appId])
    {
        return;
    }
    
    
    YDownloadObjectModel * downloadModelValue = [[YDownloadObjectModel alloc] init];
    downloadModelValue.url = [self getAppInfoApi:self.appId];
    
    self.downloadModel = downloadModelValue;
    YRelease(downloadModelValue)        
}

- (NSString *) getAppInfoApi:(NSString *) appId
{
    if ([NSString isNilOrEmpty:appId])
    {
        return nil;
    }
    
    
    NSString * result = [_GET_APPIFNO_URL_TEMPLATE_ replace:_GET_APPINFO_URL_APPID_PARAM_ with:appId];
    return result;
}
@end
